<?php /** @noinspection ALL */

//提现管理

namespace app\admin\controller;


use think\facade\Db;

class WithdrawLog {

	function getList($page=1,$pageSize=10){
		$input=input();

		$userinfo=Pubilc::check_jwt($input['token']);

		if(!$userinfo)return json(['code' => 0,'msg'=>'请重新登录']);

		$id=$userinfo->userId;

		$type=$userinfo->type;

		$condition = ' and 1=1';

		if (!empty($input['userinfo'])) {
			$input['userinfo']=trim($input['userinfo']);
			$condition .= " and (su.nick_name like '%{$input['userinfo']}%' or su.tel like '%{$input['userinfo']}%' ) ";
		}

		if (!empty($input['time'])) {
			$start=$input['time'][0]/1000;
			$end=$input['time'][1]/1000;
			$condition .= " and wl.add_time >= $start and wl.add_time <=  $end";
		}

		$withdraw_logList = Db::query("select wl.*,su.nick_name,su.real_name,su.tel,b.name,FROM_UNIXTIME(wl.add_time,'%Y-%m-%d %H:%i:%s') as add_time from withdraw_log as wl join system_user as su on su.id=wl.uid join bank as b on b.id=wl.bank_id where 1".$condition." order by wl.id desc limit ".(($page-1)*$pageSize).",$pageSize");

		$total_num = Db::query("select count(wl.id) as sum from withdraw_log as wl join system_user as su on su.id=wl.uid join user_bank as ub on ub.id=wl.bank_id where 1".$condition." order by wl.id desc ");

		if($type==2){
			$usertype=2;
		}else{
			$usertype=1;
		}

		return json(['code' => 1, 'data' => $withdraw_logList,'total_num'=>$total_num[0]['sum'],'usertype'=>$usertype]);
	}

	//修改状态
	function edit_status(){
		$input = input();

		if(empty($input['id'])) return json(['code' => 0, 'msg' => '参数错误']);

		$recharge_log = Db::table('withdraw_log')->where('id', $input['id'])->find();

		if (empty($recharge_log)) return json(['code' => 0, 'msg' => '数据不存在']);

		$result = Db::name('withdraw_log')->where('id', $input['id'])->update(['status'=>$input['status']]);

		if (!$result) return json(['code' => 0, 'msg' => '编辑失败']);

		return json(['code' => 1, 'msg' => '编辑成功']);
	}

}